//
//  Register(image).m
//  注册界面
//
//  Created by administrator on 16/8/10.
//  Copyright © 2016年 duanzhenglong. All rights reserved.
//

#import "Register(image).h"
@interface Register_image_()
@property(nonatomic,strong)UIView*BackgroundView;
@property(nonatomic,strong)UIView*Register;
@property(nonatomic,strong)UIView*shareWindow;
@property(nonatomic,strong)UIImage*image;
@property(nonatomic,strong)NSString*Name;
@property(nonatomic,strong)NSString*Descrip;
@end
@implementation Register_image_
-(UIView *)BackgroundView{
    if(_BackgroundView==nil){
        _BackgroundView=[[UIView alloc]initWithFrame:[UIScreen mainScreen].bounds];//一定要和屏幕大小一致
        _BackgroundView.backgroundColor=[UIColor colorWithRed:0/255.f green:0/255.f blue:0/255.f alpha:0.5];
        _BackgroundView.userInteractionEnabled=YES;
    }
    return _BackgroundView;
}
-(UIView *)Register{
#define Width _Register.frame.size.width
#define Height _Register.frame.size.height
    if (_Register==nil) {
        _Register=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 250, 250)];
        _Register.center=CGPointMake(self.shareWindow.frame.size.width/2, self.shareWindow.frame.size.height/3);
        _Register.backgroundColor=[UIColor whiteColor];
        _Register.layer.cornerRadius=10;
        _Register.layer.masksToBounds=YES;
        ///////////////////////////////////////
        ///图像处理
        UIImageView*imageview=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 80, 80)];
        imageview.center=CGPointMake(Width/4, Height/4);
        imageview.layer.borderWidth=1;
        imageview.tag=30;
        [_Register addSubview:imageview];
        UIButton*AddImageButton=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, 80, 30)];
        AddImageButton.center=CGPointMake(Width/4, Height/4);
        [AddImageButton setTitle:@"点击添加头像" forState:UIControlStateNormal];
        [AddImageButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        AddImageButton.titleLabel.font=[UIFont systemFontOfSize:10];
        AddImageButton.enabled=YES;
        [_Register addSubview:self];
        [_Register addSubview:AddImageButton];
        [AddImageButton addTarget:self action:@selector(AddPicture) forControlEvents:UIControlEventTouchUpInside];
        
        
        //左按钮
        UIButton*LeftBtn=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, Width/2, 50)];
        LeftBtn.center=CGPointMake(Width/4, Height*9/10);
        LeftBtn.backgroundColor=[UIColor whiteColor];
        [LeftBtn setTitle:@"取消" forState:UIControlStateNormal];
        [LeftBtn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
        LeftBtn.enabled=YES;
        [_Register addSubview:self];
        [_Register addSubview:LeftBtn];
        [LeftBtn addTarget:self action:@selector(BtnCancel) forControlEvents:UIControlEventTouchUpInside];
        //右按钮
        
        
        UIButton*RightBtn=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, Width/2, 50)];
        RightBtn.center=CGPointMake(Width*3/4, Height*9/10);
        RightBtn.backgroundColor=[UIColor whiteColor];
        [RightBtn setTitle:@"注册" forState:UIControlStateNormal];
        [_Register addSubview:self];
        [_Register addSubview:RightBtn];
        RightBtn.enabled=YES;
        [RightBtn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
        [RightBtn addTarget:self action:@selector(BtnRegister) forControlEvents:UIControlEventTouchUpInside];
        
        
        //分割线
        UIView *V1=[[UIView alloc]initWithFrame:CGRectMake(0, Height*4/5-2, Width, 1)];
        V1.backgroundColor=[UIColor grayColor];
        [_Register addSubview:V1];
        UIView*V2=[[UIView alloc]initWithFrame:CGRectMake(Width/2-2, Height*4/5, 1, 50)];
        V2.backgroundColor=[UIColor grayColor];
        [_Register addSubview:V2];
        
        
        //Label
        UILabel *NameLabel=[[UILabel alloc]initWithFrame:CGRectMake(105, Height/4-15, 40, 25)];
        NameLabel.text=@"姓名:";
        NameLabel.backgroundColor=[UIColor whiteColor];
        [_Register addSubview:NameLabel];
        UILabel*DescripLabel=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 60, 15)];
        DescripLabel.center=CGPointMake(Width/4, Height*3/5);
        DescripLabel.text=@"密码:";
        DescripLabel.backgroundColor=[UIColor whiteColor];
        [_Register addSubview:DescripLabel];
        
        
        //Text
        UITextField*NameText=[[UITextField alloc]initWithFrame:CGRectMake(NameLabel.frame.origin.x+45, Height/4-18, 80, 35)];
        NameText.textAlignment=NSTextAlignmentLeft;
        NameText.layer.borderWidth=1;
        NameText.layer.borderColor=[[UIColor grayColor] CGColor];
        NameText.tag=10;
        [_Register addSubview:NameText];
        UITextField*DescripText=[[UITextField alloc]initWithFrame:CGRectMake(NameLabel.frame.origin.x, Height/2, Width/2+15, Height/6)];
        DescripText.layer.borderColor=[[UIColor grayColor] CGColor];
        DescripText.layer.borderWidth=1;
        DescripText.tag=11;
        [_Register addSubview:DescripText];
    }
    return _Register;
}
-(void)show{
    self.shareWindow = [UIApplication sharedApplication].keyWindow;
    [self.shareWindow addSubview:self.BackgroundView];
    [self.BackgroundView addSubview:self.Register];
}
-(void)BtnCancel{
    [self.BackgroundView removeFromSuperview];
}
-(void)BtnRegister{
    UITextField*Name=(UITextField*)[self.Register viewWithTag:10];
    self.Name=[[NSString alloc]init];
    self.Name=Name.text;
    UITextField*Descrip=(UITextField*)[self.Register viewWithTag:11];
    self.Descrip=[[NSString alloc]init];
    self.Descrip=Descrip.text;
    if ([self.delegate respondsToSelector:@selector(WithImage:andName:andDescrip:)]) {
        [self.delegate WithImage:self.image andName:self.Name andDescrip:self.Descrip];
    }
    [self.BackgroundView removeFromSuperview];
}
-(void)AddPicture{
   
    NSLog(@"sdfh");
}
-(void)Image:(UIImage *)image{
    self.image=[[UIImage alloc]init];
    self.image=image;
    UIImageView*imageview=(UIImageView*)[self.Register viewWithTag:30];
    imageview.image=self.image;
    [imageview reloadInputViews];
}
@end
